#ifndef SHOWVARIABLES_H
#define SHOWVARIABLES_H

#include <stdio.h>
#include "data.h"
#include "macros.h"

struct uint16_show
{
    char type[256];
    uint16 value;
};

struct int16_show
{
    char type[256];
    int16 value;
};

struct list_show
{
    char type[256];
    uint16 data_type;
    t1B size;
    t1B* body_addr;
};


void ShowVariable(struct DataEntry* de, int name, int val)
{
    switch(de->type)
    {
        case DT_BYTE:
            if(name)
            {
                printf("DT_BYTE");
            }
            if(name&&val) printf("\t\t\t");
            if(val)
            {
                uint16 val = GET(de->pos,de->tid,t1B);
                printf("%d",val);
            }
            break;
        case DT_UINT16:
            if(name)
            {
                printf("DT_UINT16");
            }
            if(name&&val) printf("\t\t");
            if(val)
            {
                uint16 val = GET(de->pos,de->tid,uint16);
                printf("%d",val);
            }
            break;
        case DT_LIST:
            if(name)
            {
                printf("DT_LIST");
            }
            if(name&&val) printf("\t\t");
            if(val)
            {
                struct DataEntry nde;
                nde.type = GETE(de,dtype_t);
                nde.tid = de->tid;
                ShowVariable(&nde,1,0);

                nde.pos = de->pos+sizeof(dtype_t);

                list_size_t size = GET(nde.pos,de->tid,list_size_t);

                nde.pos += sizeof(list_size_t);

                printf("[");
                list_size_t i;
                for(i = 0; i < size; i++)
                {
                    ShowVariable(&nde,0,1);
                    nde.pos += tavm_data_type_size[nde.type];
                    if(i<size-1)printf(",");

                }
                printf("]");
            }
            break;
        case DT_SIGNAL:
            printf("DT_SIGNAL");
            break;

        default:
        printf("Unknown data");
        break;
    }
}

void ShowData(int tid)
{

    addr_t i;
    struct DataEntry* de;

    if(tid==TID_DATA_V) printf("Variables:\n");
    else if(tid==TID_DATA_S) printf("Statics:\n");

    for(i = 0; i < tavm_datamap_count; i++)
    {
        de = &tavm_datamap[i];

        if(tid == de->tid)
        {
            ShowVariable(de,1,1);
            printf("\n");
        }
    }
}

#endif

